exports.list = function(req, res){
	return db.user.find(function(err, data) {
      if (!err) {
        return res.send(JSON.stringify(data));
      } else {
        return res.send('Could not connect to the database');
      }
    });
	res.send('respond with a resource');
};
exports.signup = function(req, res){
	return res.render('user/signup', {
	  title: 'Register page'
	});
};
exports.login = function(req, res){
	return res.render('user/login', {
	  title: 'Login page'
	});
};
exports.authen = function(req, res){
	passport.authenticate('local-login', {
		successRedirect : '/user', // redirect to the secure profile section
		failureRedirect : '/user/login', // redirect back to the signup page if there is an error
		failureFlash : false // allow flash messages
	});
};
exports.save = function(req, res){
	var user;
	user = new db.user(req.body);
	return user.register(function(error) {
		if (error) {
			return res.send(error);
		} else {
			res.send('Registered');
		}
	});
};
exports.profile = function(req, res){
	return res.send(JSON.stringify(req.user));
};
exports.logout = function(req, res){
	req.logout();
	res.redirect('/');
};
exports.isLoggedIn = function(req, res, next) {

	// if user is authenticated in the session, carry on
	if (req.isAuthenticated())
		return next();

	// if they aren't redirect them to the home page
	res.redirect('/user/login');
}
